﻿using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Test;

namespace JWTAPI.AuthorInfo;

public static class Ids4Config
{
      public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new IdentityResource[]
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile()
            };
        }

        public static IEnumerable<ApiResource> GetApis()
        {
            return new List<ApiResource>
            {
                new ApiResource("ids4.api", "MyABenNetCore.Ids4.ResourceOwnerPassword"),
            };
        }
        public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                // 用途：模拟前后分离项目
                new Client
                {
                    ClientId = "erp",

                    // no interactive user, use the clientid/secret for authentication
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, //模式：用户密码模式

                    RequireClientSecret=true,//需要密码

                    AccessTokenLifetime=(int)TimeSpan.FromHours(8).TotalSeconds,//此属性可以设置我们申请的Token的有效时间，单位是秒，默认3600秒也就是一个小时。

                    //如果要获取refresh_tokens ,必须在scopes中加上OfflineAccess
                    AllowOfflineAccess=true,

                    AlwaysIncludeUserClaimsInIdToken = true,

                    // secret for authentication
                    ClientSecrets =
                    {
                        new Secret("erp".Sha256())
                    },

                    // scopes that client has access to 授权该client可以访问范围（scopes）为api的资源
                    AllowedScopes = { 
                        "ids4.api", 
                        IdentityServerConstants.StandardScopes.OfflineAccess,
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                    }
                },
            };
        }

        public static List<TestUser> Users = new List<TestUser>
        {
            new TestUser
            {
                SubjectId="001",
                Password="abennet01",
                Username="abennet01"
            },
            new TestUser
            {
                SubjectId="002",
                Password="abennet02",
                Username="abennet02"
            }
        };
}